#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Music(models.Model):
    """音乐
    """
    title = models.CharField(max_length=50)
    artist = models.CharField(max_length=50)
    counting = models.IntegerField()
    song = models.FileField(upload_to="song/%Y/%m")
    join_time = models.DateTimeField(auto_now=True)

    class Meta:
        pass

    class Admin:
        pass

    def __unicode__(self):
        return self.title

class Comment(models.Model):
    """用户评论
    """
    user = models.ForeignKey(User)
    music = models.ForeignKey(Music)
    rank = models.IntegerField()
    content = models.TextField(null=True, blank=True)
    send_time = models.DateTimeField(auto_now=True)

    class Meta:
        pass

    class Admin:
        pass

    def __unicode__(self):
        return "%s-%s" % (self.user.username, self.music.title, )
    

class UserMusic(models.Model):
    """用户播放列表
    """
    user = models.ForeignKey(User)
    music = models.ForeignKey(Music)
    counting = models.IntegerField()
    active = models.BooleanField(default=True)

    class Meta:
        pass

    class Admin:
        pass

    def __unicode__(self):
        return "%s: %s" % (self.user.username, self.music.title, )
    

class Category(models.Model):
    """音乐分类
    """
    title = models.CharField(max_length=50)
    description = models.CharField(max_length=500)

    class Meta:
        pass

    class Admin:
        pass

    def __unicode__(self):
        return self.title


class CategoryMusic(models.Model):
    """分类音乐列表
    """
    category = models.ForeignKey(Category)
    music = models.ForeignKey(Music)
    counting = models.IntegerField(default=0)

    class Meta:
        pass

    class Admin:
        pass

    def __unicode__(self):
        return "%s:%s" % (self.category.title, self.music.title, )
    

